      SUBROUTINE SHADEP(SOLILL)
C
C           'SHADEP' CALCULATES SWITCHING FOR THERMAL LAG DURING
C            PLANET SHADOWING
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      COMMON/IPOOL1/ IGRAV,IDAMP,IK,K1,ITIM,IAB,IAPS,IBB,IBPS,NK(10),
     .               LK(10),LLK(10)
C
      COMMON/ISHADE/ IPLANS,ISATSH,IWRTTF
C
      COMMON/ITDLAY/ ITIMIN,ISSWCH,IPDLAY,JENTRY
C
      COMMON/PLANSH/ OCCRIT,TAUPL
C
      COMMON/RPOOL1/ RHOK(10),T   ,SA(3,3),FM1(3,3),ZLK(10),OMEG(3),
     .               ZLKP(10),ZLKDP(10),CMAT(3,3),GBAR(3,3),YBCM(3),
     .               ZBZK(3,10),FCM(3,3),DTO,PHID,PHI
C
C
      IF(ITIM.EQ.2) GO TO 10
      TLAST=T
      TSAVE=T
      SISAVE=SOLILL
      SIMIN1=SOLILL
      ISSWCH=0
      IPDLAY=0
      ITIMIN=0
      JENTRY=1
      GO TO 150
C
C
   10 CONTINUE
      TEST=T-TSAVE
      IF(TEST.LE.0.0D0) GO TO 20
      TLAST=TSAVE
      TSAVE=T
      ITIMIN=1
      SIMIN1=SISAVE
      SISAVE=SOLILL
      ISSWCH=0
      GO TO 100
   20 CONTINUE
      TSAVE=T
      ITIMIN=0
      SISAVE=SOLILL
  100 CONTINUE
      IF(IPLANS.EQ.0) GO TO 150
      DELSI=SOLILL-SIMIN1
      DELT=T-TLAST
      TEST=DELSI*TAUPL/DELT
      TEST=DABS(TEST)
      IF(TEST.LT.OCCRIT) GO TO 150
      ISSWCH=1
      IF(DELSI.LT.0.0D0) ISSWCH=2
      IF(IPDLAY.EQ.ISSWCH) ISSWCH=0
  150 CONTINUE
      RETURN
      END
